@extends('layouts.master')

@section('content')
    <div class="col-sm-8 blog-main">
        <div class="blog-post">
            <h2 class="blog-post-title">{{$post->title}}</h2>
            <p class="blog-post-meta">{{$post->created_at->toFormattedDateString()}} by <a href="/about">{{$post->user->name}}</a></p>
            <p>{{$post->body}}</p>
        </div>
    </div>

    @foreach($post->comments as $comment)
        <div class="card">
            <div class="card-header">
                {{$comment->created_at->diffForHumans()}}
            </div>
            <div class="cart-block">
                <p class="card-text">{{$comment->body}}</p>
                <p class="card-text"><small class="text-muted"> by {{$comment->user->name}}</small></p>
            </div>
        </div>
        <br />
    @endforeach

    <div class="card">
        <div class="card-header">
            Add Comment
        </div>
        <div class="cart-block">
            <form method="post" action="/posts/{{$post->id}}/comment">
                {{csrf_field()}}
                <fieldset class="form-group">
                    <textarea class="form-control" id="body" name="body" rows="3" required placeholder="enter comment pls!"></textarea>
                </fieldset>
                <button type="submit" class="btn btn-primary">Submit</button>
            </form>
        </div>
    </div>

@endsection